package jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

/**
 * jedis事务操作
 */
public class TxDemo {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.10.100", 6379);
        jedis.auth("Bocon123456*");

        jedis.watch("luobinjie-key");
        jedis.unwatch();

        Transaction transaction = jedis.multi();
        transaction.watch("luobinjie-key");

        try{
            transaction.set("name", "luobinjie");
            transaction.exec();
        }catch (Exception e){
            transaction.discard();
        }finally {
            jedis.close();
        }

    }
}
